<?php

/**
 * Role base class
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: Role.php 38 2009-02-18 17:12:39Z monzee $
 */
abstract class Admin_Doctrine_Base_Role extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('roles');
        $this->hasColumn('id', 'string', 64, array('type' => 'string', 'primary' => true, 'length' => '64'));
        $this->hasColumn('description', 'string', 256, array('type' => 'string', 'length' => '256'));

        $this->option('charset', 'utf8');
    }

    public function setUp()
    {
        $this->hasMany('Admin_Doctrine_Permission as Permissions', array('local' => 'id',
                                                                         'foreign' => 'role_id'));

        $this->hasMany('Admin_Doctrine_User as Users', array('refClass' => 'Admin_Doctrine_UserRole',
                                                             'local' => 'role_id',
                                                             'foreign' => 'user_id'));

        $this->hasMany('Admin_Doctrine_Role as Children', array(
            'refClass' => 'Admin_Doctrine_RoleHeirarchy',
            'local' => 'parent_id',
            'foreign' => 'child_id',
        ));

        $this->hasMany('Admin_Doctrine_Role as Parents', array(
            'refClass' => 'Admin_Doctrine_RoleHeirarchy',
            'local' => 'child_id',
            'foreign' => 'parent_id',
        ));

    }
}
